The present invention relates to a linker using relocation sequences, and particularly but not exclusively to a method of linking, a linker, a computer program product containing relocation instructions and a method of setting up a linker to implement relocation sequences.
Linkers for producing executable programs are known. Generally speaking, a linker acts to link a number of object code modules to form a single executable program. Object code modules are usually generated from program source code modules, these modules being written a high level language. An assembler/compiler reads each source code module and assembles and/or compiles the high level language of the source code module to produce an object code module. The assembler also generates a number of relocations which are used to combine the object code module at link time in a linker.
The ELF (executable linking format) standard defines a convention for naming relocation sections belonging to a given section, e.g. reloc.abc is relocation section of section .abc. Standard relocations under the ELF format allow an offset in section data to be defined where patching is to occur and a symbol whose value is to be patched. A type field also exists which is used to describe the appropriate method of encoding the value of the symbol into the instruction or data of the section data being patched. According to the existing arrangements, the relocation type definitions are usually created on an ad hoc basis for each instruction set targeted. The 32 bit ELF standard allows only 256 distinct relocation types, so that same types are reascribed to different semantics for each instruction set.
One problem which exists with existing linking techniques is that the object code module itself needs to define the necessary relocations to implement the calculations required to patch a single location for each such location in the section data in the module. For sections requiring a plurality of relocation operations, object code modules can become bloated. Moreover, it is frequently the case that the same sequence of relocation operations may be required to be implemented on different sets of section data. According to existing techniques, it is necessary to redefine the sequence of relocations in each relocation section associated with a particular set of section data.
According to one aspect of the present invention there is provided a method of preparing an executable program from a plurality of object code modules, each module containing sets of section data and relocation instructions, wherein said relocation instructions include a compound relocation having a type field (reltype) denoting a compound type indicator and an offset field indicating the location in the section data where the compound relocation is to be effected, the method comprising: reading the section data and relocation instructions; identifying the compound type indicator and recalling a sequence of relocations associated with said type indicator; and executing the relocation operations defined in said sequence of relocations at the said location in the section data.
Another aspect of the invention provides a method of setting up a linker to implement a sequence of relocation operations at link time at an identified location in a set of section data of an object code module, the method comprising; storing a set of relocation sequences in association with respective compound type indicators, each relocation sequence comprising a sequence of relocations defining said relocation operations.
A further aspect of the invention provides a linker for preparing an executable program from a plurality of object code modules, each module containing sets of section data and relocation instructions, wherein said relocation instructions include a compound relocation having a type field (reltype) denoting a compound type indicator and an offset field indicating the location in the section data where the compound relocation is to be effected, the linker comprising: a relocation module for reading the relocation instructions and for identifying the compound type indicator of said compound relocation; a section data module for holding section data to which the relocation instructions relate; and a store holding a plurality of sets of relocation sequences in association with respective compound type indicators, wherein the relocation module executes the relocation operations defined in said sequence of relocations identified by the compound type indicator at the said location in the section data.
A further aspect of the invention provides a computer program product in the form of an object code module which contains sets of section data and relocation instructions, wherein the relocation instructions include a compound relocation having a type field denoting a compound type indicator and an offset field indicating the location in the section data where the compound relocation is to be effected, the computer program product being cooperable with a linker to cause execution of relocation operations by the linker by recalling a sequence of relocations associated with said type indicator and executing said sequence of relocations at the identified location in the section data.
Thus, according to the following described embodiments of the invention, a mechanism is defined for defining and passing compound relocations in object files. A compound relocation is a relocation that is expanded by the linker into a sequence of relocations all at the same offset. Typically, it can be a set of non-bit relocations performing some calculation followed by a bit relocation patching the value into the section. The compound relocations allow a number of advantages to be gained.
By defining a compound relocation for frequently performed calculations to encode symbols into instructions, object file bloat can be avoided.
It is possible to achieve interoperability with non-optimising linkers by interpreting non-optimising relocation types as compound relocations. Thus, the same relocation in an object code module can have two different meanings depending on the sophistication of the linker. A standard linker can treat the relocation as a simple relocation defining a single relocation operation. A more sophisticated linker of the type described herein can interpret the relocation as a compound relocation and execute a sequence of relocations depending on the indicated type.
For a better understanding of the present invention and to show how the same may be carried into effect, reference will now be made by way of example to the accompanying drawings in which: